package com.fujitsu.cn.fnst.controller;

import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fujitsu.cn.fnst.base.BaseController;
import com.fujitsu.cn.fnst.entiy.Meeting;
import com.fujitsu.cn.fnst.entiy.MeetingBook;
import com.fujitsu.cn.fnst.model.MeetingModel;
import com.fujitsu.cn.fnst.service.MeetingBookService;
import com.fujitsu.cn.fnst.service.MeetingUseService;

@Controller
public class BookController extends BaseController {
    @Resource
    private MeetingBookService meetingBookService;
    @Resource
    private MeetingUseService meetingUseService;

    @RequestMapping(value = "/book", method = RequestMethod.GET)
    public String book(Model model, HttpSession session) {
        if (!isLogin(session)) {
            redirect("/login");
        }
        return "book/book";
    }

    @RequestMapping(value = "/book/time", method = RequestMethod.GET)
    @ResponseBody
    public List<Meeting> timeModel(Model model, HttpSession session,
            String date,
            String endTime, String beginTime, String amount)
            throws ParseException {
        if (!isLogin(session)) {
            return null;
        }
        return meetingUseService.timeModel(date, beginTime, endTime, amount);

    }

    @RequestMapping(value = "/book/meeting", method = RequestMethod.GET)
    @ResponseBody
    public MeetingBook meetingModel(Model model, HttpSession session,
            int meetingId,
            String amount) {
        if (!isLogin(session)) {
            return null;
        }
        return meetingUseService.meetingModel(meetingId, amount);

    }

    @RequestMapping(value = "/book/function", method = RequestMethod.GET)
    @ResponseBody
    public MeetingBook functionModel(Model model, HttpSession session,
            int meetingId, String amount) {
        if (!isLogin(session)) {
            return null;
        }
        return meetingUseService.meetingModel(meetingId, amount);

    }

    @RequestMapping(value = "/book/other", method = RequestMethod.GET)
    @ResponseBody
    public MeetingBook otherModel(Model model, HttpSession session,
            int meetingId,
            String amount) {
        if (!isLogin(session)) {
            return null;
        }
        return meetingUseService.meetingModel(meetingId, amount);

    }
}
